package class1;

import java.util.Comparator;
import java.util.TreeMap;

public class demo2 {
    public static void main(String[] args) {
   TreeMap<Student,String>map=new TreeMap<>(new Comparator<Student>() {
       @Override
       public int compare(Student o1, Student o2) {
        int i=o1.getName().compareTo(o2.getName());

        return i==0?o1.getAge()-o2.getAge():i;
       }
   });
        Student stu1=new Student("zhangsan",15);
        Student stu2=new Student("zhangsan",18);
        Student stu3=new Student("tom",25);
        Student stu4=new Student("san",15);
map.put(stu1,"上海");
map.put(stu2,"北京");
map.put(stu3,"长春");
map.put(stu4,"贵州");


        System.out.println(map);


    }
}
